from django.db import models
from tinymce.models import HTMLField
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
#定义 分类
class Category(models.Model):
    name = models.CharField(max_length=30)
    def __str__(self):
        return self.name
#定义 标签
class Tag(models.Model):
    name = models.CharField(max_length=30)
    def __str__(self):
        return self.name
class UserInfo(models.Model):
    uname = models.CharField(max_length=20)
    upwd = models.CharField(max_length=40)
    uemail = models.CharField(max_length=30)
    isActive = models.BooleanField(default=False)
    def __str__(self):
        return self.uname


#定义 文章
class Post(models.Model):
    #标题
    title = models.CharField(max_length=250)
    #正文
    body = models.TextField()
    created_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)
    #摘要
    excerpt = models.CharField(max_length=200, blank=True,null=True)
    #文章分类，一对多
    category = models.ForeignKey(Category)
    #文章标签，多对多
    tags = models.ManyToManyField(Tag,blank=True)
    #作者
    author = models.ForeignKey(UserInfo)



    def __str__(self):
        return self.title


